# model
from script.get_user_info.problem_number.codeforces import cf_problem_number
from model.update_rating_and_solve_number.config.config import update_solve_problem_number_sleep_time
import pymongo
import time

def base_solve_problem_number(dateset , uid_name , problem_number_name , solve_problem_number):
    client = pymongo.MongoClient("mongodb://localhost:27017/")
    db = client["ACM_MEMBER"]
    collections = db[dateset]

    for collection in collections.find():
        uid = collection[uid_name]
        time.sleep(update_solve_problem_number_sleep_time)
        try :
            problem_number = solve_problem_number(uid)
        except :
            problem_number = 0
        collections.update_one({uid_name: uid}, {"$set": {problem_number_name: problem_number}})
        print(problem_number)
    client.close()

if __name__ == '__main__':
    base_solve_problem_number("CODEFORCES_INFORMATION", "codeforces_id" , "codeforces_solve_problem_number" , cf_problem_number)